package unit8;

import java.io.FileReader;
import java.io.IOException;

public class Ex8_6_Example8_6 {
    public static void main(String[] args) {
        FileReader freader = null;
        try {
            //创建FIleReader对象
            freader = new FileReader("D:\\test\\text1.txt");
            char[] temp = new char[100]; //设置一个字符读取缓冲区
            int n; //一次读取的字符个数
            while ((n = freader.read(temp)) != -1) {
                System.out.println("读取" + n + " 个字符");
                System.out.println(temp);//控制台输出读取的字符
            }
        } catch (IOException e) {
            System.out.println("文件访问异常");
            e.printStackTrace();
        }
        finally {
            try {
                if (freader != null) {
                    freader.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
